package com.lbiuse.utils.propertyUtils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class WxConfigUtils {
    private static Properties properties = new Properties();

    static {
        try {
            properties.load(WxConfigUtils.class.getClassLoader()
                    .getResourceAsStream("wechatConfig.properties"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getString(String key) {
        return properties.getProperty(key);
    }

    public static Integer getInteger(String key) {
        Integer i = null;
        try {
            String value = getString(key);
            i = Integer.parseInt(value);
        } catch (Exception e) {
            i = null;
        }
        return i;
    }

    public static Double getDouble(String key) {
        Double d = null;
        try {
            String value = getString(key);
            d = Double.parseDouble(value);
        } catch (Exception e) {
            d = null;
        }
        return d;
    }

    public static Float getFloat(String key) {
        Float f = null;
        try {
            String value = getString(key);
            f = Float.parseFloat(value);
        } catch (Exception e) {
            f = null;
        }
        return f;
    }

    public static boolean getBoolean(String key) {
        boolean b = false;
        try {
            String value = getString(key);
            b = Boolean.parseBoolean(value);
        } catch (Exception e) {
            b = false;
        }
        return b;
    }

    public static String getAppId() {
        return getString("wx.appId");
    }

    public static String getSecrect() {
        return getString("wx.appSecrect");
    }
}
